package com.lecture.java8.excel.dyr;

import com.alibaba.excel.EasyExcel;
import com.lecture.java8.excel.DemoDataListener;
import com.lecture.java8.excel.dyr.model.Model0422;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Test0422 {
    public static void main(String[] args) {
        String dir = "D:\\study\\tmp\\0422\\";
        String dataResultFileName = dir + "2011-2022所有数据.xlsx";
        DemoDataListener<Model0422> dataResultListener = new DemoDataListener<>();
        EasyExcel.read(dataResultFileName, Model0422.class,dataResultListener).sheet().doRead();
        List<Model0422> resultList = dataResultListener.getDataList();

        resultList = resultList.stream().filter(model -> {
            if (model.getName().contains("s") || model.getName().contains("S")) {
                return false;
            }
            if (model.getJ().contains("暂停上市")) {
                return false;
            }
            return true;
        }).collect(Collectors.toList());

        Map<Long, List<Model0422>> collect = resultList.stream().collect(Collectors.groupingBy(Model0422::getA));
        List<Model0422> result = new ArrayList<>();
        collect.forEach((k,v) -> {
            if (v.size() == 12) {
                result.addAll(v);
            }
        });

        result.sort((o1,o2) -> Math.toIntExact(o1.getA() - o2.getA()));

        EasyExcel.write(dir + "result.xlsx", Model0422.class)
                .sheet("a").doWrite(result);
    }
}
